home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / wild / support / profilerlibrary / profiler.i next >
Text File  |  1999-01-01  |  6KB  |  272 lines

  1.     include    exec/types.i
  2.     include    exec/lists.i
  3.     include    exec/libraries.i
  4.     include    exec/exec_lib.i
  5.     include    libraries/dos_lib.i
  6.     include    dos/dos.i
  7.     
  8.     STRUCTURE    ProfilerBase,LIB_SIZE+4
  9.         LONG    prob_UtilityBase
  10.         LONG    prob_DOSBase
  11.         LABEL    prob_SIZEOF
  12.  
  13.  
  14.     STRUCTURE    ProfilerHandler,0
  15.         APTR    ph_Pool            ; memory pool
  16.         APTR    ph_Name            ; name of the profiler session !
  17.         APTR    ph_TimerBase        ; opened for every task !
  18.         APTR    ph_TimerIO        ; to open the device !
  19.         APTR    ph_TimerMSG        ; msg port of the iorequest !
  20.         STRUCT    ph_EventList,MLH_SIZE    ; events. must be sorted in time.
  21.         APTR    ph_NextEvent        ; next event to happen.
  22.         APTR    ph_Output        ; output filehandle.
  23.         STRUCT    ph_LastShot,8        ; last event reached in that moment.
  24.         LONG    ph_Cycles        ; number of cycles
  25.         LABEL    ph_SIZEOF
  26.     
  27.     STRUCTURE    ProfilerEvent,MLN_SIZE
  28.         STRUCT    pe_ETime,8        ; last time happened...
  29.         APTR    pe_Name            ; name of the event
  30.         STRUCT    pe_Duration,8        ; the duration: time from the predent start
  31.         STRUCT    pe_Sum,8        ; sum of all cycles.
  32.         LABEL    pe_SIZE
  33.  
  34. _LVOCreateProfilerHandler    EQU    -30    ; a0:tags    ret: d0:ph
  35. _LVODeleteProfilerHandler    EQU    -36    ; a0:ph        ret:
  36. _LVOAddEvent            EQU    -42    ; a0:ph a1:tags    ret: pe
  37. _LVORemEvent            EQU    -48    ; a0:ph a1:pe    ret:
  38. _LVONewCycle            EQU    -54    ; a0:ph    
  39. _LVOEventReached        EQU    -60    ; a0:ph
  40. _LVOEndCycle            EQU    -66    ; a0:ph
  41. _LVOCreateLog            EQU    -72    ; a0:ph a1:Tags    ret: success
  42.  
  43. PROF_TAGBASE    EQU    $801EAA00
  44.  
  45. PRF_Name    EQU    PROF_TAGBASE+1    ; name of handler or event
  46. PRF_EventsArray    EQU    PROF_TAGBASE+2    ; fast way to load events: a 0 terminated array pointing to names of events.
  47. PRF_Output    EQU    PROF_TAGBASE+3    ; a output fh, for logs. 
  48.  
  49. ; CreateProfilerHandler needs PRF_Name. Optional: EventsArray & Output
  50. ; AddEvent needs PRF_Name.
  51. ; ***IMPORTANT!*** NO PRF_EventsArray management: that's only for CreateProfilerHandles.
  52. ; CreateLog needs PRF_Output if you haven't specified in CreateProfilerHandler
  53.  
  54.     IFND    FLAG_PROFILE
  55. FLAG_PROFILE    SET    1        ; that flag activates or eliminates the profiling
  56.     ENDC
  57.  
  58. PIArrayEntry    MACRO    ;\1:name
  59.         IFNC    '','\1'
  60.         dc.l    .ea\1
  61.         ENDC
  62.         ENDM
  63.  
  64. PINameEntry    MACRO    ;\1:name
  65.         IFNC    '','\1'
  66. .ea\1        dc.b    '\1',0
  67.         ENDC
  68.         ENDM
  69.  
  70. ProfilerOpen    MACRO                ; only opens the lib
  71.         IFNE    FLAG_PROFILE
  72.         movem.l    d0-d1/a0-a1/a6,-(a7)
  73.         movea.l    4.w,a6
  74.         lea.l    proname,a1
  75.         moveq.l    #0,d0
  76.         jsr    _LVOOpenLibrary(a6)
  77.         move.l    d0,_ProBase
  78.         bra    op\@
  79. _ProBase    dc.l    0
  80. proname        dc.b    'profiler.library',0
  81.         cnop    0,4
  82. op\@        movem.l    (a7)+,d0-d1/a0-a1/a6
  83.         ENDC
  84.         ENDM
  85.         
  86. ProfilerQuit    MACRO
  87.         IFNE    FLAG_PROFILE
  88.         movem.l    d0-d1/a0-a1/a6,-(a7)
  89.         movea.l    4.w,a6
  90.         movea.l    _ProBase,a1
  91.         jsr    _LVOCloseLibrary(a6)
  92.         movem.l    (a7)+,d0-d1/a0-a1/a6
  93.         ENDC
  94.         ENDM
  95.  
  96. ;example: ProfilerInit.TestApp Event1,Event2,Event3
  97.  
  98. ProfilerInit    MACRO            ; \0 is the name!!! args:\1-\i names of events!
  99.         IFNE    FLAG_PROFILE
  100.         tst.l    _ProHandle
  101.         bne    no\@
  102.         movem.l    d0-d1/a0-a1/a6,-(a7)    
  103.         movea.l    4.w,a6
  104.         lea.l    proname,a1
  105.         moveq.l    #0,d0
  106.         jsr    _LVOOpenLibrary(a6)
  107.         move.l    d0,_ProBase
  108.         beq    pi\@
  109.         movea.l    d0,a6
  110.         lea.l    prtags\@,a0
  111.         jsr    _LVOCreateProfilerHandler(a6)
  112.         move.l    d0,_ProHandle
  113.         bra    pi\@
  114. _ProHandle    dc.l    0
  115. _ProBase    dc.l    0
  116. prtags\@    dc.l    PRF_Name,tname\@
  117.         dc.l    PRF_EventsArray,evarray\@
  118.         dc.l    0,0
  119. evarray\@    PIArrayEntry    \1
  120.         PIArrayEntry    \2
  121.         PIArrayEntry    \3
  122.         PIArrayEntry    \4
  123.         PIArrayEntry    \5
  124.         PIArrayEntry    \6
  125.         PIArrayEntry    \7
  126.         PIArrayEntry    \8
  127.         PIArrayEntry    \9
  128.         PIArrayEntry    \a
  129.         PIArrayEntry    \b
  130.         PIArrayEntry    \c
  131.         PIArrayEntry    \d
  132.         PIArrayEntry    \e
  133.         PIArrayEntry    \f
  134.         PIArrayEntry    \g
  135.         PIArrayEntry    \h
  136.         PIArrayEntry    \i
  137.         dc.l    0        
  138.         PINameEntry    \1
  139.         PINameEntry    \2
  140.         PINameEntry    \3
  141.         PINameEntry    \4
  142.         PINameEntry    \5
  143.         PINameEntry    \6
  144.         PINameEntry    \7
  145.         PINameEntry    \8
  146.         PINameEntry    \9
  147.         PINameEntry    \a
  148.         PINameEntry    \b
  149.         PINameEntry    \c
  150.         PINameEntry    \d
  151.         PINameEntry    \e
  152.         PINameEntry    \f
  153.         PINameEntry    \g
  154.         PINameEntry    \h
  155.         PINameEntry    \i
  156. tname\@        dc.b    '\0',0
  157. proname        dc.b    'profiler.library',0
  158.         cnop    0,4
  159. pi\@        movem.l    (a7)+,d0-d1/a0-a1/a6
  160. no\@
  161.         ENDC
  162.         ENDM        
  163.  
  164. ProfilerStore    MACRO    ; ea
  165.         IFNE    FLAG_PROFILE
  166.         move.l    _ProHandle,\1
  167.         ENDC
  168.         ENDM
  169.  
  170. ProfilerCycle    MACRO
  171.         IFNE    FLAG_PROFILE
  172.         movem.l    d0-d1/a0-a1/a6,-(a7)
  173.         movea.l    _ProBase,a6
  174.         IFC    '','\1'
  175.         movea.l    _ProHandle,a0
  176.         ELSE
  177.         movea.l    \1,a0
  178.         ENDC
  179.         jsr    _LVONewCycle(a6)
  180.         movem.l    (a7)+,d0-d1/a0-a1/a6
  181.         ENDC
  182.         ENDM
  183.  
  184. ProfilerEvent    MACRO
  185.         IFNE    FLAG_PROFILE
  186.         movem.l    d0-d1/a0-a1/a6,-(a7)
  187.         movea.l    _ProBase,a6
  188.         IFC    '','\1'
  189.         movea.l    _ProHandle,a0
  190.         ELSE
  191.         movea.l    \1,a0
  192.         ENDC
  193.         jsr    _LVOEventReached(a6)
  194.         movem.l    (a7)+,d0-d1/a0-a1/a6
  195.         ENDC
  196.         ENDM
  197.  
  198. ProfilerEnd    MACRO
  199.         IFNE    FLAG_PROFILE
  200.         movem.l    d0-d1/a0-a1/a6,-(a7)
  201.         movea.l    _ProBase,a6
  202.         IFC    '','\1'
  203.         movea.l    _ProHandle,a0
  204.         ELSE
  205.         movea.l    \1,a0
  206.         ENDC
  207.         jsr    _LVOEndCycle(a6)
  208.         movem.l    (a7)+,d0-d1/a0-a1/a6
  209.         ENDC
  210.         ENDM
  211.  
  212. ProfilerClose    MACRO
  213.         IFNE    FLAG_PROFILE
  214.         movem.l    d0-d1/a0-a1/a6,-(a7)
  215.         movea.l    _ProBase,a6
  216.         IFC    '','\1'
  217.         movea.l    _ProHandle,a0
  218.         ELSE
  219.         movea.l    \1,a0
  220.         ENDC
  221.         jsr    _LVODeleteProfilerHandler(a6)
  222.         movea.l    a6,a1
  223.         movea.l    4.w,a6
  224.         jsr    _LVOCloseLibrary(a6)
  225.         movem.l    (a7)+,d0-d1/a0-a1/a6
  226.         ENDC
  227.         ENDM
  228.  
  229. ProfilerLog    MACRO    ; \1=filename
  230.         IFNE    FLAG_PROFILE
  231.         movem.l    d0-d2/a0-a1/a5-a6,-(a7)
  232.         movea.l    4.w,a6
  233.         lea.l    dosname\@,a1
  234.         moveq.l    #36,d0
  235.         jsr    _LVOOpenLibrary(a6)
  236.         tst.l    d0
  237.         beq    no\@
  238.         movea.l    d0,a6            ; a6:dosbase
  239.         movea.l    d0,a5            ; a5:dosbase
  240.         IFC    '','\1'
  241.         jsr    _LVOOutput(a6)
  242.         ELSE
  243.         move.l    #outname\@,d1
  244.         move.l    #MODE_NEWFILE,d2
  245.         jsr    _LVOOpen(a6)
  246.         ENDC
  247.         move.l    d0,outfh\@
  248.         movea.l    _ProBase,a6
  249.         movea.l    _ProHandle,a0
  250.         lea.l    logtags\@,a1
  251.         jsr    _LVOCreateLog(a6)
  252.         IFNC    '','\1'
  253.         move.l    outfh\@,d1
  254.         movea.l    a5,a6
  255.         jsr    _LVOClose(a6)
  256.         ENDC
  257.         movea.l    a5,a1
  258.         movea.l    4.w,a6
  259.         jsr    _LVOCloseLibrary(a6)
  260.         bra    no\@
  261. logtags\@    dc.l    PRF_Output
  262. outfh\@        dc.l    0
  263.         dc.l    0,0
  264. dosname\@    dc.b    'dos.library',0
  265.         IFNC    '','\1'
  266. outname\@    dc.b    '\1',0
  267.         ENDC
  268.         cnop    0,4
  269. no\@        movem.l    (a7)+,d0-d2/a0-a1/a5-a6
  270.         ENDC
  271.         ENDM
  272.